#!/home/up/anaconda3/envs/hyper/bin/python
#-*-coding:utf-8-*-
#注意这里import的顺序
import numpy
import rospy
from sensor_msgs.msg import Image
import sys
sys.path.remove('/opt/ros/melodic/lib/python2.7/dist-packages')
import cv2
sys.path.append('/home/up/hyper_ws/install/lib/python3/dist-packages')
from cv_bridge import CvBridge, CvBridgeError


class image_demo:
    def __init__(self):

        self.count = 0
        self.rate = rospy.Rate(10)

        self.image = None

        '''
        ros initial
        '''
        # rospy.init_node("image_subscirber", anonymous=True)

        '''
        ros subscriber
        '''
        self.ros_img_sub = rospy.Subscriber("/d435/color/image_raw/compressed", Image, self.ros_img_callback)

    def ros_img_callback(self, image_msg):
        bridge = CvBridge()
        self.image = bridge.imgmsg_to_cv2(image_msg, "bgr8")
        print('444')
        self.count = 1

    def subscriber(self):
        while not rospy.is_shutdown():

            if self.count == 0:
                continue
            print('count', self.count)
            cv2.imshow('listener', self.image)
            cv2.waitKey(3)
            cv2.destroyAllWindows()



if __name__ == '__main__':
    print('11')
    rospy.init_node("image_subscirber")
    print('22')
    image_demo1 = image_demo()
    print('33')
    image_demo1.subscriber()

